<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<head>
<title>学生成绩管理系统</title>
<link rel="stylesheet" type="text/css" id="css" href="../style/main.css" />
<link rel="stylesheet" type="text/css" id="css"
	href="../style/style1.css" />
<link rel="stylesheet" type="text/css" id="css"
	href="../style/style.css" />

<style type="text/css">
<!--
table {
	border-spacing: 1px;
	border: 1px solid #A2C0DA;
}

td, th {
	padding: 2px 5px;
	border-collapse: collapse;
	text-align: left;
	font-weight: normal;
}

thead tr th {
	height: 50px;
	background: #B0D1FC;
	border: 1px solid white;
}

thead tr th.line1 {
	background: #D3E5FD;
}

thead tr th.line4 {
	background: #C6C6C6;
}

tbody tr td {
	height: 35px;
	background: #CBE2FB;
	border: 1px solid white;
	vertical-align: middle;
}

tbody tr td.line4 {
	background: #D5D6D8;
}

tbody tr th {
	height: 35px;
	background: #DFEDFF;
	border: 1px solid white;
	vertical-align: middle;
}

tfoot tr td {
	height: 35px;
	background: #FFFFFF;
	border: 1px solid white;
	vertical-align: middle;
}
-->
</style>

<script type="text/javascript" src="../js/common.js"></script>
</head>
<c:if test="${!(empty sessionScope.message)}">
	<script type="text/javascript">
		alert('<c:out value="${sessionScope.message}"/>');
	</script>
	<c:remove var="message" scope="session" />
</c:if>
<script type="text/javascript">
	function scoreRestrict(score) {
		if (score > 100 || score < 0) {
			alert("请输入不小于0且不大于100的成绩");
			return false;
		} else {
			return true;
		}
	}


	/*如果单选框被选中使得对应记录的输入控件变为可操作，否则使得对应记录的输入控件变为不可操作*/
	function vary() {
		var boxes = document.getElementsByName("NO");
		var usualScore = document.getElementsByName("usualScore");
		var lastScore = document.getElementsByName("lastScore")
		for (var i = 0; i < boxes.length; i++) {
			if (boxes[i].checked == true) {
				usualScore[i].disabled = false;
				lastScore[i].disabled = false;
			} else {
				usualScore[i].disabled = true;
				lastScore[i].disabled = true;
			}
		}
	}
	/*使得页面所有单选框全部选中*/
	function selAllCheckbox(checkboxName) {
		o = document.getElementsByName(checkboxName);
		for (i = 0; i < o.length; i++) {
			o[i].checked = true;
		}
		vary();
	}
	/* 使得页面所有单选框不被选中 */
	function unselAllCheckbox(checkboxName) {
		o = document.getElementsByName(checkboxName);
		for (i = 0; i < o.length; i++) {
			o[i].checked = false;
		}
		vary();
	}
	/* 使得页面所有单选框被反选，即选中的变为不被选中，不被选中的变为选中 */
	function reAllCheckbox(checkboxName) {
		o = document.getElementsByName(checkboxName);
		for (i = 0; i < o.length; i++) {
			if (o[i].checked == false) {
				o[i].checked = true;
			} else {
				o[i].checked = false;
			}
		}
		vary();
	}
</script>
<script type="text/javascript">
	/*保存录入或者修改的成绩*/
	function saveScore(sourceURL, type) {
		/*通过控件名称来获得列表中所有记录的ID，将其拼接成一个字符串studentNos */
		var studentNos = "";
		var boxs = document.getElementsByName('NO');
		var studentNo = document.getElementsByName('studentNo');
		var status = document.getElementsByName('status');
		var selectFlag=false;
		
		for (var i = 0; i < boxs.length; i++){
			if (boxs[i].checked == true){
				studentNos += studentNo[i].value + ",";
				selectFlag=true;
			}
			else{	/* 控件未选中但学生成绩的提交状态为暂时提交时不允许进行永久提交 */
				if(type=='1'&&status[i].value=='0'){
					alert("永久提交必须对全部暂时成绩进行提交");
					return false;
				}
			}
		}
		if(!selectFlag)	{
			alert("没有学生被选中");
			return false;
		}
		if (studentNos.length > 0) {
			studentNos = studentNos.substr(0, studentNos.length - 1);
		}
		
		/*通过控件名称来获得列表中所有记录的录入或者修改的成绩，将其拼接成一个字符串scores */
		var usualScores = "";
		var usualScore = document.getElementsByName('usualScore');
		for (var i = 0; i < usualScore.length; i++){
			if(!scoreRestrict(usualScore[i].value)){
				return false;/*分数格式不符合要求*/
			}	
			if (usualScore[i].disabled == false)
				usualScores += usualScore[i].value + ",";
		}
		if (usualScores.length > 0) {
			usualScores = usualScores.substr(0, usualScores.length - 1);
		}
		/*通过控件名称来获得列表中所有记录的成绩备注信息，将其拼接成一个字符串remarks */
		var lastScores = "";
		var lastScore = document.getElementsByName('lastScore');
		for (var i = 0; i < lastScore.length; i++){
			if(!scoreRestrict(lastScore[i].value))	
				return false;/*分数格式不符合要求*/
			if (lastScore[i].disabled == false)
				lastScores += lastScore[i].value + ",";
		}
		if (lastScores.length > 0) {
			lastScores = lastScores.substr(0, lastScores.length - 1);
		}
		var teacherNo = myForm.teacherNoTemp.value;
		var courseNo = myForm.courseNoTemp.value;
		var tcTeacherNo = myForm.tcTeacherNoTemp.value;
		//获得当前页面上班级和课程下拉框的选定值
		document.location = sourceURL + '?action=saveGrade&usualScores=' + usualScores + '&studentNos=' + studentNos + '&lastScores=' + lastScores + '&courseNo='+ courseNo + '&teacherNo=' + teacherNo + '&tcTeacherNo='+tcTeacherNo+'&type=' + type;
	//执行路径sourceURL，并传递参数到后台，后台处理需要这些参数。参数包括：studentNos、scores、remarks三个拼接字符串，courseNo、classNo当前页面上班级和课程下拉框的选定值。
	}
</script>
<body>
	<div id="btm">
		<div id="main">
			<div id="header">
				<div id="top"></div>
				<div id="logo">
					<h1>成绩管理</h1>
				</div>
				<div id="mainnav">
					<ul>
						<li><a href="teacherIndex.jsp">首页</a></li>
						<li><a href="tcServlet?action=list">开设课程</a></li>
						<li><a href="tcServlet?action=checkGrade">成绩提交</a></li>
						<li><a href="tcServlet?action=showTeacher">信息查询</a></li>
						<li><a href="changePwd.jsp">密码修改</a></li>
						<li><a href="../logoutServlet">退出</a></li>
					</ul>
					<span> </span>
				</div>
			</div>
			<div id="content" align="center">
				<div id="center">
					<BR /> <BR />
					<form method="post" name="myForm" action="#">
						<table width="800" align="center" cellpadding="0" cellspacing="0">
							<tr>
								<input type="hidden" id="teacherNoTemp" name="teacherNoTemp"
									value="${requestScope.teacherNo }" />
								<input type="hidden" id="courseNoTemp" name="courseNoTemp"
									value="${requestScope.courseNo }" />
								<input type="hidden" id="tcTeacherNoTemp" name="tcTeacherNoTemp"
									value="${requestScope.tcTeacherNo }" />
								<td width="75%"><h3>
										成绩管理-->成绩录入&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
											href="tcServlet?action=checkGrade">返回</a>
									</h3></td>
							</tr>
							<tr>
								<td colspan="2" width="100%">
									<table width="100%">
										<thead>
											<tr>
												<th width="9%" align="center" class="line1" scope="col"
													colspan="1"><b>选择</b></th>
												<th width="12%" align="center" scope="col" colspan="1"><b>学号</b></th>
												<th width="11%" align="center" scope="col" colspan="1"><b>姓名</b>
												</th>
												<th width="12%" align="center" scope="col" colspan="1"><b>课程编号</b>
												</th>
												<th width="11%" align="center" scope="col" colspan="1"><b>课程名</b>
												</th>
												<th width="12%" align="center" colspan="1"><b>教学班号</b></th>
												<th width="11%" align="center" colspan="1"><b>平时成绩</b></th>
												<th width="11%" align="center" colspan="1"><b>期末成绩</b></th>
												<th width="12%" align="center" colspan="1"><b>提交状态</b></th>
											</tr>
										</thead>

										<tbody>
											<c:forEach items="${requestScope.list}" var="studentC">
												<c:if test="${studentC.status eq 0}">
													<tr>
														<td width="9%" align="center" colspan="1"><input
															type="checkbox" name="NO" onchange="javascript:vary();" /></td>
														<td width="12%" align="center" colspan="1">${studentC.studentNo }<input
															type="hidden" name="studentNo"
															value="${studentC.studentNo }" /></td>
														<td width="11%" align="center" colspan="1">
															${studentC.studentName }</td>
														<td width="12%" align="center" colspan="1">
															${studentC.courseNo }</td>
														<td width="11%" align="center" colspan="1">
															${studentC.courseName }</td>
														<td width="12%" align="center" colspan="1">
															${studentC.tcTeacherNo }</td>
														<td width="11%" align="center" colspan="1"><input
															disabled="disabled" type="text" size="5"
															name="usualScore" value="${studentC.usualScore }" /></td>
														<td width="11%" align="center" colspan="1"><input
															disabled="disabled" type="text" size="5" name="lastScore"
															value="${studentC.lastScore }" /></td>
														</td>
														<td width="12%" align="center" colspan="1"><input
															type="hidden" name="status" value="${studentC.status }" />暂时提交</td>
													</tr>
												</c:if>
												<c:if test="${studentC.status eq 1}">
													<tr>
														<td width="8%" align="center" colspan="1"><input
															disabled="disabled" type="checkbox" name="NO"
															onchange="javascript:vary();" /></td>
														<td width="12%" align="center" colspan="1">${studentC.studentNo }<input
															type="hidden" name="studentNo"
															value="${studentC.studentNo }" /></td>
														<td width="11%" align="center" colspan="1">
															${studentC.studentName }</td>
														<td width="12%" align="center" colspan="1">
															${studentC.courseNo }</td>
														<td width="11%" align="center" colspan="1">
															${studentC.courseName }</td>
														<td width="12%" align="center" colspan="1">
															${studentC.tcTeacherNo }</td>
														<td width="11%" align="center" colspan="1"><input
															disabled="disabled" type="text" size="5"
															name="usualScore" value="${studentC.usualScore }" /></td>
														<td width="11%" align="center" colspan="1"><input
															disabled="disabled" type="text" size="5" name="lastScore"
															value="${studentC.lastScore }" /></td>
														<td width="12%" align="center" colspan="1"><input
															type="hidden" name="status" value="${studentC.status }" />永久提交</td>
														</td>
													</tr>
												</c:if>
											</c:forEach>
											<tr>
												<td colspan="1"><input type="button" value="暂时提交"
													onclick="javascript:saveScore('tcServlet','0');" /></td>
												<td colspan="1"><input type="button" value="永久提交"
													onclick="javascript:saveScore('tcServlet','1');" /></td>
											</tr>
										</tbody>
										<tbody>
											<tr>
												<td align="center" colspan="12">选择：<a href="#"
													onclick="javascript:selAllCheckbox('NO');">全部</a>- <a
													href="#" onclick="javascript:unselAllCheckbox('NO');">不选</a>-
													<a href="#" onclick="javascript:reAllCheckbox('NO');">反选</a>
												</td>
											</tr>

										</tbody>
									</table>
								</td>
							</tr>
						</table>
					</form>

				</div>



			</div>

			<div id="footer">
				<div id="copyright">
					<div id="copy">
						<p align="center">CopyRight&copy;2010</p>
						<p>南京晓庄学院信息工程学院</p>
					</div>
				</div>
				<div id="bgbottom"></div>
			</div>

		</div>
	</div>
</body>
</html>
